{extend name="template/base" /}
{block name="content"}
{php}
use think\Db;
{/php}
<style>
    .add_btn{
        padding-top: 15px;
        width: 100%;
        text-align: center;
    }
</style>
<div class="page-container">
    <form class="form form-horizontal" id="form" method="post" action="{:\\think\\Request::instance()->baseUrl()}">
        <input type="hidden" name="id" value="{$vo.id ?? ''}">
        <input type="hidden" name="type" id="type" value="{$type}">
        <div class="row cl">
            {if $type == 'add'}
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>派车单：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <div style="width:300px;display: inline-block" class="input-text" >
                    <select name="group_id" class="select" id="group_id" style="border: solid 1px #ffffff" datatype="*" nullmsg="">
                        <option value="">请选择行程</option>
                        {foreach $group as $gv}
                        <option {if ($gv['id'] == $vo['group_id'])} selected {/if} value="{$gv.id}">{$gv.id}:{$gv.route_title}+{$gv.driver_user_name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            {else/}
            <input type="hidden" name="more" id="more" value="1">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>派车单：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <span>{$group_id}:{$route_title}+{$driver_user_name}</span>
            </div>
            {/if}
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <table class="table table-border table-bordered table-hover table-bg mt-20">
                <thead>
                <tr class="text-c">
                    {if $type == 'edit'}
                        <th>ID</th>
                    {/if}
                    <th>入住日期</th>
                    <th>酒店名称</th>
                    <th>酒店房型</th>
                    <th>入住天数</th>
                    <th>费用</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>

                {if $type == 'add'}
                    <tr class="text-c line_item">
                        <td>
                            <input type="text" class="input-text Wdate  mb-5" autocomplete="off" style="width:150px" placeholder="入住日期" name="check_in_date_{$i}" value="{$vo.check_in_date?date('Y-m-d',$vo.check_in_date):''}" {literal} onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" {/literal}>
                        </td>
                        <td>
                            <input type="text" class="input-text" style="width:150px" placeholder="请输入酒店名称" name="hName_{$i}" value="{$vo.hotel_name}" >
                        </td>
                        <td>
                            <input type="text" class="input-text" style="width:150px" placeholder="请输入酒店房型" name="hType_{$i}" value="{$vo.room_type_name}" >
                        </td>
                        <td>
                            <input type="text" class="input-text" style="width:150px" placeholder="入住天数" name="days_{$i}" value="{$vo.days}" >
                        </td>
                        <td>
                            <input type="text" class="input-text" style="width:150px" placeholder="房型费用" name="unit_price_{$i}" value="{$vo.unit_price}" >
                        </td>
                        <td>
                            <button type="button" class="btn btn-danger radius del_item">删除</button>
                        </td>
                    </tr>
                {else/}
                    {volist id="vo" name="list"}
                    <tr class="text-c line_item">
                        <td>
                            <span>{$vo.id}</span>
                            <input type="hidden" class="input-text" style="width:150px" name="dhe_id_{$i}" value="{$vo.id}" >
                        </td>
                        <td>
                            <input type="text" class="input-text Wdate  mb-5" autocomplete="off" style="width:150px" placeholder="入住日期" name="check_in_date_{$i}" value="{$vo.check_in_date?date('Y-m-d',$vo.check_in_date):''}" {literal} onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" {/literal}>
                        </td>
                        <td>
                            <input type="text" class="input-text" style="width:150px" placeholder="请输入酒店名称" name="hName_{$i}" value="{$vo.hotel_name}" >
                        </td>
                        <td>
                            <input type="text" class="input-text" style="width:150px" placeholder="请输入酒店房型" name="hType_{$i}" value="{$vo.room_type_name}" >
                        </td>
                        <td>
                            <input type="text" class="input-text" style="width:150px" placeholder="入住天数" name="days_{$i}" value="{$vo.days}" >
                        </td>
                        <td>
                            <input type="text" class="input-text" style="width:150px" placeholder="房型费用" name="unit_price_{$i}" value="{$vo.unit_price}" >
                        </td>
                        <td>
                            <!--<button type="button" class="btn btn-danger radius del_item">删除</button>-->
                        </td>
                    </tr>
                    {/volist}
                {/if}

                </tbody>
            </table>
        </div>
        <div class="add_btn">
            <button type="button" class="btn btn-primary radius" onClick="addItem()">添加条目</button>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">备注：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <textarea class="textarea" placeholder="备注" name="remark" value="{$vo.remark ?? ''}" >{$vo.remark ?? ''}</textarea>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>


</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script>
    function choiceHotel(e) {
        console.log('123',$(e).val())
        $.ajax({
            type: 'post',
            url: '/admin/hotel/get_hotel_room_type',
            data: {
                id:$(e).val()
            },
            success: function (data) {
                if($("#room_type_id").children().length>1){
                    $("#room_type_id").children().remove()
                    $("#room_type_id").append("<option value=''>请选择酒店房型</option>");
                }
                if (data.code == 1) {
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {

                    });
                } else {
                    if(data.length>1){
                        for(var i = 0;i < data.length;i++){
                            $("#room_type_id").append("<option {if ("+data[i]['room_type_id']+" == $vo['room_type_id'])} selected {/if} value='"+data[i]['room_type_id']+"'>"+data[i]['room_name']+"</option>");
                        }
                    }
                   console.log('data',data)
                }
            },
            error: function (data) {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                });
                console.log('data', data);
            }
        });
    }
    function checkNull(e) {
        if($(e).children().length <= 1){
            var hotel = $("#hotel_id").val();
            if(hotel == '' || typeof hotel == undefined || hotel == null){
                layer.msg('请先选择酒店', {
                    icon: 2,
                    time: 2000
                });
            }else{
                layer.msg('该酒店无房型', {
                    icon: 2,
                    time: 2000
                });
            }
        }
    }
    $(function () {

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form").Validform({
            tiptype: 2,
            ajaxPost: true,
            showAllError: true,
            callback: function (ret){
                if(ret.code == 0){
                    layer.msg(ret.msg, {
                        icon: 1,
                        time: 2000
                    },function () {
                        window.parent.location.reload(); //刷新父页面
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引\
                        parent.layer.close(index)
                    });
                }else{
                    ajax_progress(ret);
                }
            }
        });
    })


    if($("#type").val() == 'edit'){
        var index = '{$count}';
        index = parseInt(index)+1
    }else{
        var index = 1;
    }
    // 添加条目

    function addItem() {
        if('{$type}' == 'add'){
            var item = `
            <tr class="text-c line_item">
                <td>
                    <input type="text" class="input-text Wdate  mb-5" autocomplete="off" style="width:150px" placeholder="入住日期" name="check_in_date_${index}" value="{$vo.check_in_date?date('Y-m-d',$vo.check_in_date):''}" {literal} onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" {/literal}>
                </td>
                <td>
                    <input type="text" class="input-text" style="width:150px" placeholder="请输入酒店名称" name="hName_${index}" value="{$vo.days}" >
                </td>
                <td>
                    <input type="text" class="input-text" style="width:150px" placeholder="请输入酒店房型" name="hType_${index}" value="{$vo.days}" >
                </td>
                <td>
                    <input type="text" class="input-text" style="width:150px" placeholder="入住天数" name="days_${index}" value="{$vo.days}" >
                </td>
                <td>
                    <input type="text" class="input-text" style="width:150px" placeholder="房型费用" name="unit_price_${index}" value="{$vo.unit_price}" >
                </td>
                <td>
                    <button type="button" class="btn btn-danger radius del_item">删除</button>
                </td>
            </tr>
        `
        }else{
            var item = `
            <tr class="text-c line_item">
                <td>
                    <input type="hidden" class="input-text" style="width:150px" name="dhe_id_${index}" value="" >
                </td>
                <td>
                    <input type="text" class="input-text Wdate  mb-5" autocomplete="off" style="width:150px" placeholder="入住日期" name="check_in_date_${index}" value="{$vo.check_in_date?date('Y-m-d',$vo.check_in_date):''}" {literal} onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" {/literal}>
                </td>
                <td>
                    <input type="text" class="input-text" style="width:150px" placeholder="请输入酒店名称" name="hName_${index}" value="{$vo.days}" >
                </td>
                <td>
                    <input type="text" class="input-text" style="width:150px" placeholder="请输入酒店房型" name="hType_${index}" value="{$vo.days}" >
                </td>
                <td>
                    <input type="text" class="input-text" style="width:150px" placeholder="入住天数" name="days_${index}" value="{$vo.days}" >
                </td>
                <td>
                    <input type="text" class="input-text" style="width:150px" placeholder="房型费用" name="unit_price_${index}" value="{$vo.unit_price}" >
                </td>
                <td>
                    <button type="button" class="btn btn-danger radius del_item">删除</button>
                </td>
            </tr>
        `
        }

        $('.line_item').parent().append(item);
        index += 1;
    }

    // 删除条目
    $('body').on('click', '.del_item', function() {
        var len = $('.text-c').length;
        if(len > 2){
            $(this).closest('.text-c').remove();
        }else{
            layer.msg('只剩一个了', {
                time: 2000
            })
        }
    })
</script>
{/block}
